<!DOCTYPE html>
<html>

	<head>
		<meta charset="utf-8">
		<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
		<title>订单详情</title>

		<link rel="stylesheet" type="text/css" href="../css/mui.min.css" />
		<link rel="stylesheet" type="text/css" href="../css/iconfont.css" />
		<link rel="stylesheet" type="text/css" href="../css/own.css" />

	</head>

	<body>

		<header class="mui-bar mui-bar-nav">
			<button type="button" class="mui-action-back mui-btn  mui-btn-link mui-pull-left own-button">
			<span class="mui-action-back mui-icon mui-icon-left-nav own-left-nav-color"></span>
			<span class="own-left-nav-color">返回</span>
		</button>
			<h1 class="mui-title">订单详情</h1>
		</header>
		<div>
			<div class="mui-content" style="margin-left: 5%; margin-top: 80px;">
				<p style="font-size: 18px; color: #000000;">订单编号：<span id="orderId"></span></p>
				<p style="font-size: 18px; color: #000000;">服务时间：<span id="serviceDate"></span></p>
				<p style="font-size: 18px; color: #000000;">服务类型：<span id="productName"></span></p>
				<p style="font-size: 18px; color: #000000;">总金额：<span id="pTotal"></span><span></span></p>
				<p style="font-size: 18px; color: #000000;">服务姓名：<span id="shipname"></span></p>
				<p style="font-size: 18px; color: #000000;">服务电话：<span id="Phone"></span></p>
				<p style="font-size: 18px; color: #000000;">服务地址：<span id="shipaddress"></span></p>
				<p style="font-size: 18px; color: #000000;" hidden="hidden" id="detailId"></p>
				<p style="font-size: 18px; color: #000000;" hidden="hidden" id="productId"></p>
				
			</div>
			<div style="text-align: center;">
				<p id="pay" style="display: none; margin-left: 10%; width: 80%; margin-top: 40px; background-color: #04BB21; height: 40px; font-size: 20px;border-radius: 8px;color: #FFFFFF;line-height: 40px;">前往支付</p>

				<p id="trailer" style="display: none; margin-left: 10%; width: 80%; margin-top: 40px; background-color: #04BB21; height: 40px; font-size: 20px;border-radius: 8px;color: #FFFFFF;line-height: 40px;">取消订单</p>
				<p id="sub" style="display: none; margin-left: 10%; width: 80%; margin-top: 40px; background-color: #04BB21; height: 40px; font-size: 20px;border-radius: 8px;color: #FFFFFF;line-height: 40px;">确认完成</p>
				<p id="evaluation" style="display: none; margin-left: 10%; width: 80%; margin-top: 40px; background-color: #04BB21; height: 40px; font-size: 20px;border-radius: 8px;color: #FFFFFF;line-height: 40px;">前往评价</p>
			</div>
		</div>


		<script type="text/javascript" src="../js/jquery-1.11.1.min.js"></script>
		<script src="../js/mui.min.js" charset="UTF-8"></script>
		<script src="../js/own.js" charset="UTF-8"></script>
		<script>
			mui.plusReady(function() {

				
				var data = {};

				var self = plus.webview.currentWebview();

				data = JSON.parse(self.dataStr);
				//var version = self.shipname;

				//var shipnames=shipname;
				document.getElementById("serviceDate").innerHTML = data.serviceDate;
				document.getElementById("pTotal").innerHTML = data.pTotal + "元";
				document.getElementById("productName").innerHTML = data.productName;
				document.getElementById("shipname").innerHTML = data.servicePerson;
				document.getElementById("Phone").innerHTML = data.servicePersonPhone;
				document.getElementById("shipaddress").innerHTML = data.province + " " + data.city + " " + data.area + " " + data.shipAddress;
				document.getElementById("orderId").innerHTML = data.orderId;
				document.getElementById("detailId").innerHTML = data.detailId;
				document.getElementById("productId").innerHTML = data.productId;
					var evaluation = document.getElementById("evaluation");
				//评价跳转

				evaluation.addEventListener('tap', function() {

					mui.openWindow({
						url: '../mine/evaluation.html',
						id: '../mine/evaluation.html',
						extras: {
							orderId:data.orderId,
							detailId:data.detailId,
							productId:data.productId 
						}

					});
				});
				
				
				var pay = document.getElementById("pay");
				//document.getElementById("sub").innerHTML = status;

				pay.addEventListener('tap', function() {

					mui.openWindow({
						url: '../mine/pay.html',
						id: '../mine/pay.html',
						extras: {
							dataStr: self.dataStr
						}

					});
				});

				var status = data.status;

				if(status == "预约中" || status == "待支付") {
					document.getElementById("trailer").style.display = "";
				}
				if(status == "已服务") {
					document.getElementById("sub").style.display = "";
				}
			
				if(status == "待支付") {
					document.getElementById("pay").style.display = "";
					document.getElementById("trailer").style.display = "none";
				}
				if(status == "待评价") {
					document.getElementById("evaluation").style.display = "";
				}
				
				var sub = document.getElementById("sub");

				sub.addEventListener("tap", function() {

					var data = {};
					data.accountId = plus.storage.getItem("accountId");
					data.tokenCode = plus.storage.getItem("tokenCode");
					data.orderId = document.getElementById("orderId").innerHTML;
					//alert(123)
					$.ajax({
						url: url + "rest/confirmOrder",
						type: "POST",
						data: data,
						success: function(result) {
							//返回json字符串，转成json对象进行属性获取

							result = JSON.parse(result);
						
							if(result.status != '0') {
								mui.alert(result.msg + "!");

								//	plus.webview.currentWebview().reload()

							} else {
								mui.toast("确认完成");
								var ws = plus.webview.currentWebview();
								plus.webview.close(ws);

								var list = plus.webview.getWebviewById('template-sub-first.html');
								//触发列表界面的自定义事件（refresh）,
								//alert(list.id);
								mui.fire(list, 'refresh');

								//ar Scanner = plus.webview.getWebviewById('template-sub-first.html');

								//触发前往页面的自定义事件（例：AddNew）,从而进行数据刷新
								//mui.fire(Scanner,'AddNew');

								/*
								 * 自定义back事件 返回刷新
								 */

								/*	mui.plusReady(function() {
										var parentview = plus.webview.currentWebview().opener();
										parentview.reload(true);
										plus.webview.currentWebview().close();
									});*/

							}
						}
					});

				});


					var trailer = document.getElementById("trailer");

				trailer.addEventListener("tap", function() {
						
					var data = {};
					data.accountId = plus.storage.getItem("accountId");
					data.tokenCode = plus.storage.getItem("tokenCode");
					data.orderId = document.getElementById("orderId").innerHTML;
					mui.ajax(url + 'rest/cancelOrder', {
						data: data,
						dataType: 'json', //服务器返回json格式数据
						type: 'post', //HTTP请求类型
						timeout: 10000, //超时时间设置为10秒；      
						success: function(result) {
							//result = JSON.parse(result);

							if(result.status != '0') {
								mui.alert(result.msg + "!");
								//	plus.webview.currentWebview().reload()

							} else {
								mui.toast("取消成功");
								var ws = plus.webview.currentWebview();
								plus.webview.close(ws);

								var list = plus.webview.getWebviewById('template-sub-first.html');
								//触发列表界面的自定义事件（refresh）,
								//alert(list.id);
								mui.fire(list, 'refresh');

							}

						},
						error: function(xhr, type, errorThrown) {
							//异常处理；
							console.log(type);
						}
					});

				});
				
				
				
			
				
				
				

			});
		</script>

	</body>

</html>